<%@ tag body-content="empty" pageEncoding="UTF-8" isELIgnored="false" import="com.bio.utils.Pagination"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="p"%>
<%@ attribute name="pager" required="true" rtexprvalue="true" type="com.bio.utils.Pager"%>
<%@ attribute name="url" required="true" rtexprvalue="true"%>
<%@ attribute name="namespace" required="false" rtexprvalue="true"%>
<%@ attribute name="params" required="false" rtexprvalue="true"%>
<script type="text/javascript" src="/medicalManager/js/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
<!--
var url = "<s:url action="%{#attr['url']}" namespace="%{#attr['namespace']}" />";

function gotoPage(page) {
	var tmp = "";
	if(url.indexOf("?") >= 0) {
		tmp = url + "&currentIndex=" + page;
	} else {
		tmp = url + "?currentIndex=" + page;
	}
   var params = "${params}";
   if (params != '') {
       tmp = tmp + "&" + params;
   }
	window.location.href = tmp;
}

function goToPage(v) {
    var total = '${pager.pagination.pageTotal}';
    if (v == '') {
        alert('没有此页号！');
        return;
    }
    v = parseInt(v);
    total = parseInt(total);
    if (v < 1 || v > total) {
         alert('没有此页号！');
         return;
    }
    var goIndex = (v-1) * '${pager.pagination.max}';
    gotoPage(goIndex);
    
}

function replaceStr(val) {
   if(isNaN(val)) {//非数字
       var r = $("#pageGo").val().replace(val,val.substring(0,val.length-1));
       $("#pageGo").val(r)
   }
}
//-->
</script>
 <div id="divPage">
<%
    Pagination pagination = pager.getPagination();
    this.getJspContext().setAttribute("pagination",pagination);
    int pageTotal = pagination.getPageTotal();
    int ind = 0;
    if (pageTotal > 1) {
    	ind = (pageTotal-1) * pagination.getMax();
    }
    int curIndex = pagination.getCurrentIndex();
    if (curIndex > ind || pagination.getTotal() <= 0) {
%>
        <table width="100%" border="0" bgcolor="#ffcccc">
            <tr>
                <td align="center">无相关分页数据</td>
            </tr>
        </table>
<%
   }else if (pageTotal != 1 && curIndex % pagination.getMax() != 0) {
%>
		<table width="100%" border="0" bgcolor="#ffcccc">
            <tr>
                <td align="center">你输入的分页索引不正确！</td>
            </tr>
        </table>
<%
   }else {
%>
<table width="100%" border="0" bgcolor="">
          <tbody>
            <tr>
              <td align="left" width="40%">共[${pagination.pageTotal }]页 第[${pagination.pageNo}]页 共[${pagination.total }]条记录</td>
              <td align="right" width="60%">
                                     到第<input type="text" name="pageGo" id="pageGo" value="${pagination.pageNo}" style="width:40px;" onkeyup="replaceStr(this.value)">页<input type="button" value="Go" onclick="goToPage($('#pageGo').val())">
              <%
                  if (pagination.getCurrentIndex() >= 1) {
              %>
              
                	  <a href="javascript: gotoPage(0)">首页</a>
              <%
                  }else{
              %>
                	  首页
              <%
                  }
                  if (pagination.hasPreviousPage()) {
              %>
                	  <a href="javascript: gotoPage(${pagination.previousIndex })">上一页</a>
              <%
                  }else{
              %>
                	  上一页
              <%
                  }
                  
                  if (pagination.hasNextPage()) {
              %>
                	  <a href="javascript: gotoPage(${pagination.nextIndex })">下一页</a>
              <%
                  }else{
              %>
                	  下一页
              <%
                  }
                  
                  if (pagination.getCurrentIndex()+pagination.getMax()<pagination.getTotal()) {
                	  
              %>
                	  <a href="javascript: gotoPage(${(pagination.pageTotal-1)*pagination.max})">尾页</a>
              <%
                  }else{
              %>
                	  尾页
              <%
                  }
              %>
              </td>
            </tr>
          </tbody>
    </table>
<%
   }
%>
</div>